const globalIp = getApp().globalData.userIp
Page({
  /**
   * 页面的初始数据
   */
  data: {
    selected: 1,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    list: [{
      pagePath: "/template/company/addorder/addorder",
      iconPath: "/images/cailiao/addC.png",
      selectedIconPath: "/images/cailiao/addO.png",
      text: "新增订单"
    }, 
    {
      pagePath: "/template/company/addorder/addorderrecord/addorderrecord",
      iconPath: "/images/cailiao/recordC.png",
      selectedIconPath: "/images/cailiao/recordO.png",
      text: "提交记录"
    }],
    // 条件搜索
    screen:"订单状态",
    screenDown: {screenDown:["全部","审核中","已转正式单","已取消","客户申请撤回"],screen:0},
    screenFlag: false,//控制综合下拉框是否显示
    screenColor: false,
    dataColor: false,
    dataTime:"提交日期", 
    dataTime1:"起始日期",
    dataTime2:"截止日期",
    dataFlag: false, //控制综合下拉框是否显示
    infoValue: '',
    nameCall: '精确搜索',
    nameColor: false,
    nameFlag: false,
    nameCallInfo: '',
    // 数据
    alreadyOrder:[]

  },

  toDetail: function(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: './recordterm/recordterm?item=' + item,
    })
  },

  screenShow: function () {//综合下拉
    if (this.data.screenFlag){
      this.setData({
        screenFlag : !this.data.screenFlag,
        dataFlag: false,
        dataColor: false,
        nameFlag: false,
        nameColor: false
      })
    }else{
      this.setData({
        screenFlag: !this.data.screenFlag,
        dataFlag: false,
        dataColor: false,
        nameFlag: false,
        nameColor: false
      })
    }
  },

  screenChoice:function(e){//综合下拉选择子项
    console.log(e)
    this.setData({
      screen: e.currentTarget.dataset.item,
      "screenDown.screen": e.currentTarget.dataset.index,
      screenFlag: false,
      screenColor: true,
    })
    this.alreadyShow()
  },

  dataShow: function () {//日期下拉
    if (this.data.dataFlag){
      this.setData({
        dataFlag : !this.data.dataFlag,
        screenFlag: false,
        screenColor: false,
        nameFlag: false,
        nameColor: false
      })
    }else{
      this.setData({
        dataFlag: !this.data.dataFlag,
        screenFlag: false,
        screenColor: false,
        nameFlag: false,
        nameColor: false
      })
    }
  },

  changeDate1(e) {
    console.log(e)
    this.setData({
      dataTime1: e.detail.value,
      // dataFlag: false,
      dataColor: true
    })
  },
  changeDate2(e) {
    this.setData({
      dataTime2: e.detail.value,
      dataFlag: false,
      dataColor: true
    })
    this.alreadyShow()
  },

  nameShow: function () {//综合下拉
    if (this.data.nameFlag){
      this.setData({
        nameFlag : !this.data.nameFlag,
        screenFlag: false,
        screenColor: false,
        dataFlag: false,
        dataColor: false
      })
    }else{
      this.setData({
        nameFlag: !this.data.nameFlag,
        screenFlag: false,
        screenColor: false,
        dataFlag: false,
        dataColor: false
      })
    }
  },

  getInputValue:function(e) {
    this.setData({
      nameCallInfo: e.detail.value
    })
  },

  selectData: function(){
    this.setData({
      nameFlag: false,
      nameColor: true
    })
    // this.alreadyShow();
  },

  switchTab(e) {
    const data = e.currentTarget.dataset
    const url = data.path
    wx.redirectTo({url})
    // this.setData({
    //   selected: data.index
    // })
  },

  alreadyShow: function(){
    var that = this;
    wx.showLoading({
      title: '数据加载中...',
    })
    wx.request({
      url: globalIp + 'home/ordr/xcxOrderVer3',
      data: {
        sdate: that.data.dataTime1 == '起始日期' ? '' : that.data.dataTime1,
        edate: that.data.dataTime2 == '截止日期' ? '' : that.data.dataTime2,
        openId: wx.getStorageSync('userInfo').openid,
        status: parseInt(that.data.screenDown.screen) || 0,
        value: "1"
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        that.setData({
          alreadyOrder: res.data.jsonObject.data
        })
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },

  apply(e) {
    let that = this;
    wx.showModal({
      title: '申请撤回',
      content: '是否确认申请撤回',
      success: function (sm) {
        if (sm.confirm) {
          let item = e.currentTarget.dataset.item
          wx.request({
            url: globalIp + 'home/ordr/xcxOrderVer1', 
            data: {
              docEntry: item,
              value: "2",
              openId: wx.getStorageSync('userInfo').openid || '',
            },
            header: {
              'content-type': 'application/json'
            },
            method: 'POST',
            success: function(res) {
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
              setTimeout(() => {
                that.onShow();
              }, 2000)
            }
          })
        } 
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.alreadyShow()
  },

})